<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
Class Index extends MY_Controller
{
    public function __construct()
    {
        parent::__construct();
        $this->data['controller'] = 'index';
        $this->load->model('Mindex');
    }
    
    public function index()
    {
            die('');
    }
	
	public function getRestaurantLabel()
    {
        $time = $this->getParamString('time');
        die(json_encode($this->Mindex->getRestaurantLabelDb($time)));
    }
    
    public function getStaticData()
    {
        $time = $this->getParamString('time');
//        $zone=  $this->getParamString('zone');
        die(json_encode($this->Mindex->getStaticDataDb($time)));
    }
    
    public function getSlideZone(){
       // $time = $this->getParamString('time');
        $zone=  $this->getParamString('zone');
        die(json_encode($this->Mindex->getSlideZoneDb($zone)));
    }
    public function getSlideCoupon(){
       // $time = $this->getParamString('time');
        $zone=  $this->getParamString('zone');
        die(json_encode($this->Mindex->getSlideCouponDb($zone)));
    }
    public function getSlideRestaurant(){
       // $time = $this->getParamString('time');
        $zone=  $this->getParamString('zone');
        die(json_encode($this->Mindex->getSlideRestaurantDb($zone)));
    }
    
    public function getAllSlide(){
       // $time = $this->getParamString('time');
//        $zone=  $this->getParamString('zone');
        die(json_encode($this->Mindex->getAllSlideDb()));
    }
    
    public function getProvince()
    {
        die(json_encode($this->Mindex->getProvinceDb()));
    }
    
    public function getRestaurantDetail()
    {
        $restaurant_id = $this->getParamInt('restaurant_id');
        $user_id = $this->getParamInt('user_id');
       // $zone = $this->getParamInt('zone');
//        die(json_encode($this->Mindex->getRestaurantDetailDb($restaurant_id,$zone)));
        die(json_encode($this->Mindex->getRestaurantDetailDb($restaurant_id,$user_id)));
    }
	
    public function getincentivedetail(){
            $incentive_id = $this->getParamInt('incentive_id');
            die(json_encode($this->Mindex->getIncentiveDetail($incentive_id)));
    }
	
//    public function getnearrestaurant()
//    {
//		$restaurantid = $this->getParamInt('restaurantid');
//		$locationid = $this->getParamInt('locationid');		
//        die(json_encode($this->Mindex->getNearRestaurant($restaurantid,$locationid)));
//    }
        
    public function getnearrestaurant()
    {
            $restaurantid = $this->getParamInt('restaurantid');
//            $restaurant_name = $this->getParamString('restaurant_name');
            $zone = $this->getParamInt('zone');		
            die(json_encode($this->Mindex->getNearRestaurant($restaurantid,$zone)));
    }
    
    public function addLikeRestaurant(){
        $restaurant_id = $this->getParamInt('restaurant_id');
        $user_id = $this->getParamInt('user_id');
        die(json_encode($this->Mindex->addLikeRestaurantDb( $restaurant_id,$user_id)));
    }
    
    public function hotRestaurant(){
        $zone= $this->getParamInt('zone');
        $limit = $this->getParamInt('limit');
        $page = $this->getParamInt('page');
        die(json_encode($this->Mindex->hotRestaurantDb($zone,$limit,$page)));
    }
    
    public function myRestaurant(){
        $zone= $this->getParamInt('zone');
        $limit = $this->getParamInt('limit');
        $page = $this->getParamInt('page');
        $user_id = $this->getParamInt('user_id');
        die(json_encode($this->Mindex->myRestaurantDb($zone,$limit,$page,$user_id)));
    }
    
     public function getApp(){
        die(json_encode($this->Mindex->getAppDb()));
    }
    
    public function getTerm(){
        die(json_encode($this->Mindex->getTermDb()));
    }
    
    public function getQuestion(){
        die(json_encode($this->Mindex->getQuestionDb()));
    }
    
    public function listZone(){
        die(json_encode($this->Mindex->listZoneDb()));
    }
    
    public function delImage()
    {
        
        $img=$this->getParamString('img');
        $img=  urldecode($img);
        $signature=$this->getParamString('signature');
        $code=$this->getParamString('code');
        $checkSignature=hash_hmac("sha256", $code, 'khoaitayran201291@gmail.com:skype:tungnt2o12');
        
        if ($signature == $checkSignature)
        {
            $arrayImg=  explode(',', $img);
            foreach ($arrayImg as $value)
            {
                if (!in_array($value, array('', null, '0')))
                {
                    @unlink(UPLOAD . '/data/' . $value);
                }
            }
            return die(json_encode((object) array('status' => '200', 'description' => 'Xóa thành công')));
        } else
        {
            return die(json_encode((object) array('status' => '201', 'description' => 'Chữ kí không đúng')));
        }
    }
     public function getToken()
    {
        $user_id = $this->getParamInt('user_id');
        $key = $this->getParamString('key');
        $type = $this->getParamString('type');
        die(json_encode($this->Mindex->getKeyDb($user_id ? $user_id : 0, $key, $type)));
    }
     public function getStatic()
    {
        die(json_encode($this->Mindex->getStatic()));
    }
    
    public function setApp()
    {
        $key = $this->getParamString('key');           //token key
        $user_id = $this->getParamInt('user_id');   //id user
        $type = $this->getParamInt('type');      //type=1:ios,2:android,3:winphone
        $getNotice = $this->getParamInt('get_notice'); //0 là 0 nhận thông báo coupon từ cửa hàng quan tâm,1 là nhận
        $numberNotice = $this->getParamInt('number_notice'); //số lượng thông báo muốn nhận trong 1 ngày,0 là không giới hạn
        $before=$this->getParamInt('before_notice');   //nhắc nhở hết hạn trước bao ngày,0 là ko nhắc
        //còn tham số rung và âm báo để sau
        die(json_encode($this->Mindex->setAppDb($key,$user_id,$type,$getNotice,$numberNotice,$before)));
    }
    
    public function getSetApp()
    {
        $key = $this->getParamString('key');           //token key
        $user_id = $this->getParamInt('user_id');   //id user
        $type = $this->getParamInt('type');      //type=1:ios,2:android,3:winphone
        //còn tham số rung và âm báo để sau
        die(json_encode($this->Mindex->getSetAppDb($key,$user_id,$type)));
    }
    
    public function pushByToken()
    {
        $message = $this->getParamString('message');
        $key = $this->getParamString('key');
        $type = $this->getParamString('type');
        die(json_encode($this->Mindex->pushByTokenDb($message, $key, $type)));
    }
    
    public function syncaddcoupon(){
		$arr_codecoupon = json_decode(stripslashes($this->getParamString('arr_codecoupon')), true);
		$data_coupon = json_decode(stripslashes($this->getParamString('data_coupon')), true);
		$data_coupon['content'] = $data_coupon['content'];
		$wicard_id_user = $this->getParamInt('wicard_id_user');
		die(json_encode($this->Mindex->syncaddcoupon($arr_codecoupon, $data_coupon, $wicard_id_user)));
	}
}
